package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.dragon.repository.entity.Equipment;
import com.dragon.repository.entity.Loan;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 设备 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-11-29
 */
@Mapper
public interface EquipmentMapper extends BaseMapper<Equipment> {

    @Select("<script> " +
            "SELECT M.* FROM ( " +
            "      SELECT DISTINCT de.*, " +
            "      dss.scheduling_id as schedulingId  FROM dragon_equipment de " +
            "      LEFT JOIN dragon_scheduling_son dss ON de.id = dss.equipment_id AND dss.type &lt;&gt; 2 " +
            "      " +
            ") M where 1=1  " +
            "<if test='type != null '>" +
            " and M.type = #{type} " +
            "</if>" +
            "</script>")
    List<Equipment> selectListBy(Integer type);

    /**
     * 获取 排产单id
     */
    @Select("SELECT DISTINCT dsss.scheduling_id FROM dragon_equipment de " +
            "LEFT JOIN dragon_scheduling_son_son dsss ON de.id = dsss.equipment_id AND dsss.type = 1 where de.id  = #{equipmentId}  ")
    Integer getSchedulingIdByEquipmentId(Integer equipmentId);
}
